﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using SonCa.SocialNetwork.Web.ASCX.IPresenters;
using Core.Interfaces;
using System.ComponentModel.Composition;
using Core.DataAccess;
using Core.BusinessLogic.Interfaces;
using Core.Common;

namespace SonCa.SocialNetwork.Web.ASCX.Presenters
{
    public class CommentPresenter
    {
        private IComment _view;
        [Import]
        private ICommentService _commentService;
        [Import]
        private IWebContext _webContext;

        public CommentPresenter()
        {
            MEFManager.Compose(this);
        }

        public void Init(IComment view)
        {
            _view = view;
        }

        public void AddComment(string comment)
        {
            Account currentUser = _webContext.CurrentUser as Account;
            _commentService.SaveComment(new Comment {SystemObjectID = _view.SystemObjectID, SystemObjectRecordID = _view.SystemObjectRecordID, Body = comment, CommentByAccountID= currentUser.AccountID, CreateDate = DateTime.Now });
        }

        public void LoadComment()
        {
            _view.LoadComment(_commentService.GetCommentBySytemObject(_view.SystemObjectID, _view.SystemObjectRecordID));
        }

    }
}